//
//  XiaoPiaoSetVC.m
//  LazyCat
//
//  Created by linhui on 15/12/16.
//  Copyright (c) 2015年 zhanshu. All rights reserved.
//

#import "XiaoPiaoSetVC.h"
#import "AFNetworkHandler.h"
#import "ShopManagerCell.h"
@interface XiaoPiaoSetVC ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>

{
    UITableView *_tableView;
    NSMutableArray *_dataArray;
    NSMutableArray *_dataArray2;
    UIButton *_doneBtn;
}

@end

@implementation XiaoPiaoSetVC
- (void)viewDidLoad {
    [super viewDidLoad];
    [self createUI];
}
- (void)createUI {
    self.view.backgroundColor = BackColor;
    self.automaticallyAdjustsScrollViewInsets=NO;
    [self initNav:@"打印小票设置" doBack:YES];
    _dataArray=[[NSMutableArray alloc]init];
    _dataArray2 = [[NSMutableArray alloc]init];
    NSArray *timeArr = @[@"打印机名",@"打印宽度",@"打印标题",@"打印地址",@"打印电话",@"字体大小",@"打印LOGO",@"自动打印"];
    NSArray *placeHold = @[@"",@"",@"请输入打印标题",@"请输入打印地址",@"请输入打印电话",@"最小为9号，最大为20号",@"",@""]; 
    [_dataArray2 addObjectsFromArray:placeHold];
    [_dataArray addObjectsFromArray:timeArr];
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64) style:UITableViewStyleGrouped];
    _tableView.dataSource=self;
    _tableView.delegate=self;
    _tableView.scrollEnabled = NO;
    [self.view addSubview:_tableView];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
    tap.cancelsTouchesInView = NO;
    [_tableView addGestureRecognizer:tap];
    _doneBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    _doneBtn.frame = CGRectMake(10, ScreenHeight - 50, ScreenWidth - 20, 40);
    [_doneBtn setTitle:@"保存" forState:UIControlStateNormal];
    [_doneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _doneBtn.backgroundColor = MainColor;
    [_doneBtn addTarget:self action:@selector(doneBtnClick) forControlEvents:UIControlEventTouchUpInside];
    _doneBtn.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    _doneBtn.layer.cornerRadius = 5;
    _doneBtn.clipsToBounds = YES;
    [self.view addSubview:_doneBtn];
}
#pragma mark - 保存按钮
- (void)doneBtnClick {
    [self.view endEditing:YES];
}
-(void)tapAction {
    [self.view endEditing:YES];
}
#pragma mark -- tableView代理
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ShopManagerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"managercell"];
    if(cell==nil){
        cell = [[NSBundle mainBundle]loadNibNamed:@"ShopManagerCell" owner:nil options:nil][0];
    }
    cell.leftLabel.text = _dataArray[indexPath.row];
    cell.rightTextField.tag = 100 + indexPath.row;
    cell.rightTextField.delegate = self;
    cell.rightTextField.placeholder = _dataArray2[indexPath.row];
    cell.rightTextField.hidden = NO;
    if (indexPath.row == 6 || indexPath.row == 7) {
        UISwitch *changeSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        changeSwitch.onTintColor=  MainColor;
        [changeSwitch addTarget:self action:@selector(switchChangedValue:) forControlEvents:UIControlEventValueChanged];
        changeSwitch.transform = CGAffineTransformMakeScale(0.9, .9);
        [changeSwitch addTarget:self action:@selector(switchChangedValue:) forControlEvents:UIControlEventValueChanged];
        changeSwitch.tag = indexPath.row;
        cell.accessoryView = changeSwitch;
        cell.rightTextField.hidden = YES;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)switchChangedValue:(UISwitch *)sender {
    if (sender.tag == 6) {//打印logo
        
    }else if (sender.tag == 7){//自动打印
        
    }
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    return YES;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 1;
}



@end
